<?php

require("function/util.php");

$year 			= $_GET['year'];
$month 			= $_GET['month'];
$date 			= $_GET['date'];
$bus_id 		= $_GET['bus_id'];
$hash	 		= $_GET['hash'];

//$input_time = $month."/".$date."/".$year." 03:00:00";
//$begin_time = strtotime($input_time);
//$end_time = strtotime("+23 hours 59 minutes 59 seconds",$begin_time);

//$begin_time = 1346174188;
//$end_time = 1346174228;

//$current_time = "09/01/2012 02:59:59";
//$ts1 = strtotime($current_time);
//$ts2 = strtotime("+1 day",$ts1);

//$d = getdate($end_time);

//echo $ts1."<br>";
//echo $ts2."<br>";

//echo $d['month']."-".$d['mday']."-".$d['year']." ".$d['hours']."-".$d['minutes']."-".$d['seconds'];

$input_hash = $month.$date.$year.$bus_id;

if ( $hash ==  report_encode($input_hash) )
{
	$timezone = "Asia/Bangkok";
	if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone);
	$input_time 	= $month."/".$date."/".$year." 03:00:00";
	$begin_time 	= strtotime($input_time);
	$end_time 		= strtotime("+23 hours 59 minutes 59 seconds",$begin_time);
	echo $input_time."<br>";
	echo $begin_time."<br>";
	echo $end_time."<br>";
//	$begin_time 	= 1346174188;
//	$end_time 		= 1346174228;
	
	echo "<html>";
	echo "<body>";
	echo "<table border='1'>";
	echo "<tr>";
	echo "<th>Date</th>";
	echo "<th>Time</th>";
	echo "<th>Customer ID</th>";
	echo "<th>Number of Stamps</th>";
	echo "</tr>";

	$sql = "SELECT * from stamp_transaction WHERE strn_created_date >= $begin_time AND strn_created_date <= $end_time AND strn_bus_id=$bus_id";
	echo $sql;
	$result = runSQL($sql);
	while ($data = mysql_fetch_assoc($result))
	{
		$strn_cus_id 		= $data['strn_cus_id'];
		$strn_num 			= $data['strn_num'];
		$strn_created_date 	= $data['strn_created_date'];
		$d 					= getdate($strn_created_date);
		echo "<tr>";
		echo "<td>";
		echo date("F-j-Y", $strn_created_date);
		echo "</td>";
		echo "<td>";
		echo date("H:i:s", $strn_created_date);
		echo "</td>";
		echo "<td>";
		echo $strn_cus_id;
		echo "</td>";
		echo "<td>";
		echo $strn_num;
		echo "</td>";	
		echo "</tr>";
	}

	echo "</table>";
	echo "</body>";
	echo "</html>";

	} else
{

	echo "hash error";

}

?>